using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VLRJOUR
    {
        public DataRow Convert2LRJOUR(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryLRJOUR(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["LRJMANDANT"] = " ".PadRight(2 ); 
         dwReturn["LRJREZART"] = " ".PadRight(1 ); 
         dwReturn["LRJREZNR"] = " ".PadRight(10 ); 
         dwReturn["LRJREZST"] = " ".PadRight(1 ); 
         dwReturn["LRJAENDZL"] = " ".PadRight(0 ); 
         dwReturn["LRJPOSA"] = " ".PadRight(0 ); 
         dwReturn["LRJPOSN"] = " ".PadRight(0 ); 
         dwReturn["LRJTYPA"] = " ".PadRight(1 ); 
         dwReturn["LRJKOMPA"] = " ".PadRight(14 ); 
         dwReturn["LRJKONZA"] = " ".PadRight(10 ); 
         dwReturn["LRJBEZUGA"] = " ".PadRight(1 ); 
         dwReturn["LRJFLOTTEA"] = " ".PadRight(2 ); 
         dwReturn["LRJVISKOA"] = " ".PadRight(0 ); 
         dwReturn["LRJABRUFA"] = " ".PadRight(0 ); 
         dwReturn["LRJCOPUREA"] = " ".PadRight(6 ); 
         dwReturn["LRJZUSATZA"] = " ".PadRight(2 ); 
         dwReturn["LRJMETHODEA"] = " ".PadRight(0 ); 
         dwReturn["LRJRAKELARTA"] = " ".PadRight(3 ); 
         dwReturn["LRJDRUCKA"] = " ".PadRight(0 ); 
         dwReturn["LRJFUELLHOEA"] = " ".PadRight(0 ); 
         dwReturn["LRJTYPN"] = " ".PadRight(1 ); 
         dwReturn["LRJKOMPN"] = " ".PadRight(14 ); 
         dwReturn["LRJKONZN"] = " ".PadRight(10 ); 
         dwReturn["LRJBEZUGN"] = " ".PadRight(1 ); 
         dwReturn["LRJFLOTTEN"] = " ".PadRight(2 ); 
         dwReturn["LRJVISKON"] = " ".PadRight(0 ); 
         dwReturn["LRJABRUFN"] = " ".PadRight(0 ); 
         dwReturn["LRJCOPUREN"] = " ".PadRight(6 ); 
         dwReturn["LRJZUSATZN"] = " ".PadRight(2 ); 
         dwReturn["LRJMETHODEN"] = " ".PadRight(0 ); 
         dwReturn["LRJRAKELARTN"] = " ".PadRight(3 ); 
         dwReturn["LRJDRUCKN"] = " ".PadRight(0 ); 
         dwReturn["LRJFUELLHOEN"] = " ".PadRight(0 ); 
         dwReturn["LRJGRUND"] = " ".PadRight(8 ); 
         dwReturn["LRJAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["LRJAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["LRJAENDZEIT"] = " ".PadRight(0 ); 
         dwReturn["LRJLAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["LRJLAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["LRJLAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["LRJSART"] = " ".PadRight(1 ); 
         dwReturn["LRJFILLER"] = " ".PadRight(24 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapLRJOUR(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveLRJOUR(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryLRJOUR(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapLRJOUR(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertLRJOUR(dwLocal, ITXDBVERSION);
            }
            UpdateLRJOUR(dwLocal);
        }
        public void InsertLRJOUR(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO LRJOUR(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryLRJOUR(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM LRJOUR WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM LRJOUR  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "LRJOUR";
            Return = Result;
            return Return;
        }
        public void DeleteLRJOUR(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM LRJOUR   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateLRJOUR(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE LRJOUR SET "
                    +"LRJMANDANT= :LRJMANDANT,"
                    +"LRJREZART= :LRJREZART,"
                    +"LRJREZNR= :LRJREZNR,"
                    +"LRJREZST= :LRJREZST,"
                    +"LRJAENDZL= :LRJAENDZL,"
                    +"LRJPOSA= :LRJPOSA,"
                    +"LRJPOSN= :LRJPOSN,"
                    +"LRJTYPA= :LRJTYPA,"
                    +"LRJKOMPA= :LRJKOMPA,"
                    +"LRJKONZA= :LRJKONZA,"
                    +"LRJBEZUGA= :LRJBEZUGA,"
                    +"LRJFLOTTEA= :LRJFLOTTEA,"
                    +"LRJVISKOA= :LRJVISKOA,"
                    +"LRJABRUFA= :LRJABRUFA,"
                    +"LRJCOPUREA= :LRJCOPUREA,"
                    +"LRJZUSATZA= :LRJZUSATZA,"
                    +"LRJMETHODEA= :LRJMETHODEA,"
                    +"LRJRAKELARTA= :LRJRAKELARTA,"
                    +"LRJDRUCKA= :LRJDRUCKA,"
                    +"LRJFUELLHOEA= :LRJFUELLHOEA,"
                    +"LRJTYPN= :LRJTYPN,"
                    +"LRJKOMPN= :LRJKOMPN,"
                    +"LRJKONZN= :LRJKONZN,"
                    +"LRJBEZUGN= :LRJBEZUGN,"
                    +"LRJFLOTTEN= :LRJFLOTTEN,"
                    +"LRJVISKON= :LRJVISKON,"
                    +"LRJABRUFN= :LRJABRUFN,"
                    +"LRJCOPUREN= :LRJCOPUREN,"
                    +"LRJZUSATZN= :LRJZUSATZN,"
                    +"LRJMETHODEN= :LRJMETHODEN,"
                    +"LRJRAKELARTN= :LRJRAKELARTN,"
                    +"LRJDRUCKN= :LRJDRUCKN,"
                    +"LRJFUELLHOEN= :LRJFUELLHOEN,"
                    +"LRJGRUND= :LRJGRUND,"
                    +"LRJAENDBEN= :LRJAENDBEN,"
                    +"LRJAENDDAT= :LRJAENDDAT,"
                    +"LRJAENDZEIT= :LRJAENDZEIT,"
                    +"LRJLAUFKRS= :LRJLAUFKRS,"
                    +"LRJLAUFLFD= :LRJLAUFLFD,"
                    +"LRJLAUFPOS= :LRJLAUFPOS,"
                    +"LRJSART= :LRJSART,"
                    +"LRJFILLER= :LRJFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("LRJMANDANT", OracleType.NVarChar).Value = dwData["LRJMANDANT"].ToString(); 
          or1.Parameters.Add("LRJREZART", OracleType.NVarChar).Value = dwData["LRJREZART"].ToString(); 
          or1.Parameters.Add("LRJREZNR", OracleType.NVarChar).Value = dwData["LRJREZNR"].ToString(); 
          or1.Parameters.Add("LRJREZST", OracleType.NVarChar).Value = dwData["LRJREZST"].ToString(); 
          or1.Parameters.Add("LRJAENDZL", OracleType.NVarChar).Value = dwData["LRJAENDZL"].ToString(); 
          or1.Parameters.Add("LRJPOSA", OracleType.NVarChar).Value = dwData["LRJPOSA"].ToString(); 
          or1.Parameters.Add("LRJPOSN", OracleType.NVarChar).Value = dwData["LRJPOSN"].ToString(); 
          or1.Parameters.Add("LRJTYPA", OracleType.NVarChar).Value = dwData["LRJTYPA"].ToString(); 
          or1.Parameters.Add("LRJKOMPA", OracleType.NVarChar).Value = dwData["LRJKOMPA"].ToString(); 
          or1.Parameters.Add("LRJKONZA", OracleType.NVarChar).Value = dwData["LRJKONZA"].ToString(); 
          or1.Parameters.Add("LRJBEZUGA", OracleType.NVarChar).Value = dwData["LRJBEZUGA"].ToString(); 
          or1.Parameters.Add("LRJFLOTTEA", OracleType.NVarChar).Value = dwData["LRJFLOTTEA"].ToString(); 
          or1.Parameters.Add("LRJVISKOA", OracleType.NVarChar).Value = dwData["LRJVISKOA"].ToString(); 
          or1.Parameters.Add("LRJABRUFA", OracleType.NVarChar).Value = dwData["LRJABRUFA"].ToString(); 
          or1.Parameters.Add("LRJCOPUREA", OracleType.NVarChar).Value = dwData["LRJCOPUREA"].ToString(); 
          or1.Parameters.Add("LRJZUSATZA", OracleType.NVarChar).Value = dwData["LRJZUSATZA"].ToString(); 
          or1.Parameters.Add("LRJMETHODEA", OracleType.NVarChar).Value = dwData["LRJMETHODEA"].ToString(); 
          or1.Parameters.Add("LRJRAKELARTA", OracleType.NVarChar).Value = dwData["LRJRAKELARTA"].ToString(); 
          or1.Parameters.Add("LRJDRUCKA", OracleType.NVarChar).Value = dwData["LRJDRUCKA"].ToString(); 
          or1.Parameters.Add("LRJFUELLHOEA", OracleType.NVarChar).Value = dwData["LRJFUELLHOEA"].ToString(); 
          or1.Parameters.Add("LRJTYPN", OracleType.NVarChar).Value = dwData["LRJTYPN"].ToString(); 
          or1.Parameters.Add("LRJKOMPN", OracleType.NVarChar).Value = dwData["LRJKOMPN"].ToString(); 
          or1.Parameters.Add("LRJKONZN", OracleType.NVarChar).Value = dwData["LRJKONZN"].ToString(); 
          or1.Parameters.Add("LRJBEZUGN", OracleType.NVarChar).Value = dwData["LRJBEZUGN"].ToString(); 
          or1.Parameters.Add("LRJFLOTTEN", OracleType.NVarChar).Value = dwData["LRJFLOTTEN"].ToString(); 
          or1.Parameters.Add("LRJVISKON", OracleType.NVarChar).Value = dwData["LRJVISKON"].ToString(); 
          or1.Parameters.Add("LRJABRUFN", OracleType.NVarChar).Value = dwData["LRJABRUFN"].ToString(); 
          or1.Parameters.Add("LRJCOPUREN", OracleType.NVarChar).Value = dwData["LRJCOPUREN"].ToString(); 
          or1.Parameters.Add("LRJZUSATZN", OracleType.NVarChar).Value = dwData["LRJZUSATZN"].ToString(); 
          or1.Parameters.Add("LRJMETHODEN", OracleType.NVarChar).Value = dwData["LRJMETHODEN"].ToString(); 
          or1.Parameters.Add("LRJRAKELARTN", OracleType.NVarChar).Value = dwData["LRJRAKELARTN"].ToString(); 
          or1.Parameters.Add("LRJDRUCKN", OracleType.NVarChar).Value = dwData["LRJDRUCKN"].ToString(); 
          or1.Parameters.Add("LRJFUELLHOEN", OracleType.NVarChar).Value = dwData["LRJFUELLHOEN"].ToString(); 
          or1.Parameters.Add("LRJGRUND", OracleType.NVarChar).Value = dwData["LRJGRUND"].ToString(); 
          or1.Parameters.Add("LRJAENDBEN", OracleType.NVarChar).Value = dwData["LRJAENDBEN"].ToString(); 
          or1.Parameters.Add("LRJAENDDAT", OracleType.NVarChar).Value = dwData["LRJAENDDAT"].ToString(); 
          or1.Parameters.Add("LRJAENDZEIT", OracleType.NVarChar).Value = dwData["LRJAENDZEIT"].ToString(); 
          or1.Parameters.Add("LRJLAUFKRS", OracleType.NVarChar).Value = dwData["LRJLAUFKRS"].ToString(); 
          or1.Parameters.Add("LRJLAUFLFD", OracleType.NVarChar).Value = dwData["LRJLAUFLFD"].ToString(); 
          or1.Parameters.Add("LRJLAUFPOS", OracleType.NVarChar).Value = dwData["LRJLAUFPOS"].ToString(); 
          or1.Parameters.Add("LRJSART", OracleType.NVarChar).Value = dwData["LRJSART"].ToString(); 
          or1.Parameters.Add("LRJFILLER", OracleType.NVarChar).Value = dwData["LRJFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
